package com.shxc.smarttrade.old.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.shxc.smarttrade.R;
import com.shxc.smarttrade.old.bean.EventDatas;
import com.shxc.smarttrade.old.constants.EventContents;

import org.greenrobot.eventbus.EventBus;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Created by jcdev1 on 2017/6/12.
 */

public class RechargeResultActivity extends BaseActivity {
    @BindView(R.id.tv_center)
    TextView tvCenter;
    @BindView(R.id.tv_right)
    TextView tvRight;
    @BindView(R.id.iv_status)
    ImageView ivStatus;
    @BindView(R.id.tv_recharge_status)
    TextView tvRechargeStatus;
    @BindView(R.id.tv_excharge_rate)
    TextView tvExchargeRate;
    @BindView(R.id.tv_china_yuan)
    TextView tvChinaYuan;
    @BindView(R.id.btn_goon_recharge)
    Button btnGoonRecharge;
    @BindView(R.id.btn_look_detail)
    Button btnLookDetail;
    @BindView(R.id.btn_again_recharge)
    Button btnAgainRecharge;
    @BindView(R.id.tv_rechagre_num)
    TextView tvRechargeNum;
    private double rmbAmount;
    private double dollar;
    private double rate;
    private int status;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_recharge_result);

        initView();
    }

    private void initView() {
        Intent intent = getIntent();
        rmbAmount = intent.getDoubleExtra("rmbAmount", 0);
        dollar = intent.getDoubleExtra("dollar", 0);
        rate = intent.getDoubleExtra("rate", 0);
        status = intent.getIntExtra("status", 0);
        if (status == 0) {
            tvCenter.setText("充值成功");
            ivStatus.setBackgroundResource(R.mipmap.recharge_right);
            tvRechargeStatus.setText("充值成功");
            tvRechargeNum.setText("$" + dollar);
            tvExchargeRate.setText("" + rate);
            tvChinaYuan.setText("¥" + rmbAmount);
        } else {
            tvCenter.setText("充值失败");
            ivStatus.setBackgroundResource(R.mipmap.recharge_error);
            tvRechargeStatus.setText("充值失败");
            tvRechargeNum.setText("$" + dollar);
            tvExchargeRate.setText("" + rate);
            tvChinaYuan.setText("¥" + rmbAmount);
            btnGoonRecharge.setVisibility(View.GONE);
            btnLookDetail.setVisibility(View.GONE);
            btnAgainRecharge.setVisibility(View.VISIBLE);
        }
        tvRight.setText("完成");
    }

    @OnClick({R.id.tv_right, R.id.btn_goon_recharge, R.id.btn_look_detail, R.id.btn_again_recharge})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.tv_right:
                if (status == 0) {//成功
                    finish();
                } else {//失败
                    finish();
                }
                break;
            case R.id.btn_goon_recharge:
                finish();
                break;
            case R.id.btn_look_detail:
                startActivity(new Intent(this, AccountInfomationActivity.class));
                EventBus.getDefault().post(new EventDatas(EventContents.RECHARGE_RESULT_ACTIVITY_TWO, null));
                finish();
                break;
            case R.id.btn_again_recharge:
                finish();
                break;
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();

    }
}
